package com.eascs.admin.o2o.o2ozx.serviceimpl;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.o2o.o2ozx.dao.O2oZxDao;
import com.eascs.admin.o2o.zx.entity.O2oLoanUserEntityZx;
import com.eascs.admin.o2o.zx.service.IO2oLoanUserService;
import com.eascs.app.dao.PageResult;
import com.eascs.crm.common.custnew.service.CustomerService;
import com.eascs.workflow.common.service.sequence.SequenceService;

@Service
public class O2oLoadUserZxServiceImpl implements IO2oLoanUserService{
	
	@Reference
	CustomerService customerService;
	
	@Autowired
	O2oZxDao o2oZxDao;
	
	@Reference
	private SequenceService sequenceService;



	public O2oLoanUserEntityZx getEntityById(String id) {
		
		return o2oZxDao.getById(O2oLoanUserEntityZx.class, id);
	}
	

	public O2oLoanUserEntityZx getEntityByZxNo(String id) {
		String sql = "SELECT ol.* from o2o_loan_user_zx ol WHERE  ol.zx_no = ? ";
		return o2oZxDao.findEntity(sql, O2oLoanUserEntityZx.class, id);
	}
	/**
	 * @Description:
	 *               <p>
	 *               脱敏
	 *               </p>
	 * @author LMX
	 * @date 2018年3月6日 下午2:39:02
	 */
	public O2oLoanUserEntityZx getEntityByZxNo_sensitive(String id) {
		String sql = "SELECT CONCAT(LEFT(ol.user_phone, 3),'****',RIGHT(ol.user_phone, 3)) AS user_phone,CONCAT(LEFT(ol.document_no, 3),'****',RIGHT(ol.document_no, 3)) AS document_no from o2o_loan_user_zx ol WHERE  ol.zx_no = ? ";
		return o2oZxDao.findEntity(sql, O2oLoanUserEntityZx.class, id);
	}
	
	public PageResult<Object[]> loanFqZxbg(String IdNum){
		return o2oZxDao.loanFqZxbg(IdNum);
	}
	
	public PageResult<Object[]> loanFqZxbgNew(String IdNum, String bankLoanName){
		return o2oZxDao.loanFqZxbgNew(IdNum, bankLoanName);
	}
	
	@Override
	public int update(O2oLoanUserEntityZx arg0) {
		
		return o2oZxDao.updateById(arg0);
	}


	@Override
	public int add(O2oLoanUserEntityZx o2oLoanUserEntityZx) {
		// TODO Auto-generated method stub
		return o2oZxDao.insert(o2oLoanUserEntityZx);
	}
	
	/**
	 *检查身份证是否可以有征信流程在走
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public int checkO2ozx(String idCard) {
		String sql = "select count(*) from o2o_zx where id in("
				+ "select zx_no from o2o_loan_user_zx where document_no =?) and zx_status !='CLO' and is_del='N' ";
		int i = o2oZxDao.findInteger(sql, idCard);
		return i;
	}

}
